/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

/**
 *
 * @author Chen Zhe
 */
@Entity
public class OutletSeatArea implements Serializable {

    private static long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private Long outletId;
    private String areaName;
    @OneToMany(fetch = FetchType.EAGER, cascade = {CascadeType.ALL}, mappedBy = "area")
    private List<Timeslot> timeslots = new ArrayList<Timeslot>();
    private String pathName;
    private List<Integer> numDiners = new ArrayList<Integer>();

    public void create(Long outletId, String areaName, String pathName) {
        this.outletId = outletId;
        this.areaName = areaName;
        this.pathName = pathName;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getOutletId() {
        return outletId;
    }

    public void setOutletId(Long outletId) {
        this.outletId = outletId;
    }

    public String getAreaName() {
        return areaName;
    }

    public void setAreaName(String areaName) {
        this.areaName = areaName;
    }

    public List<Timeslot> getTimeslots() {
        return timeslots;
    }

    public void setTimeslots(List<Timeslot> timeslots) {
        this.timeslots = timeslots;
    }

    public String addTimeslot(Timeslot t) {
        for (Timeslot t1 : this.getTimeslots()) {
            if (t1.getTsTime().intValue() == t.getTsTime().intValue()) {
                return "duplicate";
            }
        }
        this.timeslots.add(t);
        return "successful";
    }

    public void deleteTimeslot(Timeslot slot) {
        this.timeslots.remove(slot);
    }

    @Override
    public String toString() {
        return "Id:" + this.id + " Name:" + this.areaName;
    }

    public String getPathName() {
        return pathName;
    }

    public void setPathName(String pathName) {
        this.pathName = pathName;
    }

    public List<Integer> getNumDiners() {
        return numDiners;
    }

    public void setNumDiners(List<Integer> numDiners) {
        this.numDiners = numDiners;
    }

    public void addNumDiner(Integer aNumDiner) {
        this.numDiners.add(aNumDiner);
    }
}
